require 'dgo/table/table'
require 'dgo/geometry/rectangle'

module EventEditor
  class MapMoveControler
    include DGO::Geometry
    attr_reader :sx, :sy
    def initialize(model, sx = 0, sy= 0)
      @model = model
      @target = nil
      @sx = sx
      @sy = sy
    end

    def set_signals(target)
      @event_list_panel.signal_connect('key-press-event') do |widget, event|

      end
    end
    
    def target=(target)
      @target = target
    end
    

    def on_double_clicked(event)
      @target.sx, @target.sy = @target.get_abs_location(event.x, event.y)

    end
    
    def on_left_down(event)
      @target.sx, @target.sy = @target.get_abs_location(event.x, event.y)  
      @sx = @target.sx
      @sy = @target.sy
      self.refresh_screen
    end

    def on_left_up(event)
    
    end
    
    def on_right_down(event)

    end

    def on_right_up(event)

    end
    
    def on_motion_right(event)
    end
    
    def on_motion_left(event)
    end
    
    def on_motion(event)
        if @target.left_pressed
          self.on_motion_left(event) 
        end
        if @target.right_pressed
          self.on_motion_right(event)
        end
        self.refresh_screen
    end
    
    def refresh_screen
      @target.invalidate(false) if @target
    end
    
    def render(s)
      @target.frame.render(s, @target.grid_width, @target.grid_height, @sx - @target.scroll_x_count, @sy - @target.scroll_y_count)
    end
  end
end